#pragma once
#ifndef CPAIRED_READ_SET_H_
#define CPAIRED_READ_SET_H_
#include "FileOutputBuffer.h"
#include "ReadsFileParser.h"
#include "ReadInBitsSet.h"
#include "ReadInBits.h"
#include "ColorSpaceRead.h"
#include "ShortReadUtil.h"
#include "MismatchScores.h"
#include "ReadsQualScores.h"
#include <vector>
#include <iostream>
#include <string>
using namespace std;

class CPairedReadsSet
{
public:
    CPairedReadsSet(void);
    CPairedReadsSet(unsigned int Capacity, unsigned int uiReadLength);
    // Generate set given a file with reads and readLength (must be known in advance)
    CPairedReadsSet(const char* InputFile, const char* fileFormat,\
                    unsigned int uiReadLength, bool in5to3cat3to5Format, unsigned int allowedNumOfNinRead, unsigned int readStartIndex = 0);
    virtual ~CPairedReadsSet();
    void clearReads(int capacity);
    void removeExtraTags(void);
    void getQualityScoresFromQUAL(void);
    bool handleBadRead(void);
    void flushParser(void);
    void ignoreQScores(void);
    // unsigned int get_next_capacity_reads_pairs_from_single_file(void);

    CReadInBitsSet* F_Reads;
    CReadInBitsSet* R_Reads;
    inline bool isSOLiDReadFormat(void) {
        // return(F_Reads->isSOLiDReadFormat() && R_Reads->isSOLiDReadFormat());
        return(this->cFileType == 'Q' || this->cFileType == 'S');
    }
    inline bool bGetQScores(void) {
        return(this->cFileType == 'Q' || this->cFileType == 'q');
    }
    inline void save_next_read_id(char sep = ',') {
        this->F_Reads->save_next_read_id(sep);
        this->R_Reads->save_next_read_id(sep);
    }
    unsigned int allowedNumOfNinRead;
    unsigned int  uiRead_Length;
    unsigned int  uiNo_of_Reads;
    unsigned int  uiNo_of_Bad_Reads;
    bool in5to3cat3to5Format;
    // A char flag used to record the input file type, example F for fasta, S for .seq.txt, A for .realign
    char cFileType;
    char InputFile[FILENAME_MAX];
    // Keep the info of the quality score
    CReadsQualScores* pQualScoresF;
    CReadsQualScores* pQualScoresR;
protected:
    void init(const char* InputFile, const char* fileFormat,\
              unsigned int expReadStrLineLength, bool in5to3cat3to5Format, unsigned int allowedNumOfNinRead, unsigned int readStartIndex = 0);
    // get reads from the file and store (append) in a vector. Return how many reads are read-in.
    unsigned int openAFileReady2GetRead(const char* InputFile, const char* fileFormat,  unsigned int uiExpReadsStrLength, bool bDiscardReadsWN = false);
    void save_next_read_id(const char* tagLine, char sep = ',');
    CReadsFileParser parser;
    unsigned int getExpReadLength(unsigned int getExpReadLength);
    inline void syncFileType(void) {
        this->F_Reads->cFileType = this->cFileType;
        this->R_Reads->cFileType = this->cFileType;
    };
private:
    int initialization(void);
};
#endif
